﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/SystemManagers/SystemManagers.master"
    Inherits="System.Web.Mvc.ViewPage<IEnumerable<QualificationLevel>>" %>

<%@ Import Namespace="ViewRes" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%:SystemManagersStrings.Planning%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptsContent" runat="server">
    <script src="<%:Url.Content("~/Scripts/Diploma.js")%>" type="text/javascript"> </script>
    <script type="text/javascript">

        var levelId;
        var loadPlaningsControlLink;

        $(function () {
            $("#LevelsSelect").change(function () {
                var level = $(this).val();
                if (level == "")
                    return false;
                levelId = level;
                loadPlaningsControlLink = '<%:Url.RouteUrl("Default", new {controller = "TimeLine", action = "LoadPlaningsControl"})%>';

                $("#planings").load(loadPlaningsControlLink, function () {

                });

            });
        });

        function editGlobalTaskStatus(link, div) {
            openDialog(link, 'Изменение статуса контрольной точки', function () {
                var datePickerScriptFilePath = '<%:Url.Content("~/Scripts/")%>' + 'ui.datepicker-' + '<%=ViewData["LocalLanguage"]%>' + '.js';
                $.ajax({
                    url: datePickerScriptFilePath,
                    dataType: 'script',
                    async: false,
                    success: function () {
                        $("#StartDate").datepicker($.datepicker.regional['<%=ViewData["LocalLanguage"]%>']);
                        $("#divDialog form").attr("onSuccess", "loadPlaningsControl();");
                    }
                });
            });
        }

        function editTask(link, div) {
            openDialog(link, '<%:SystemManagersStrings.EditTask%>', function () {
                var datePickerScriptFilePath = '<%:Url.Content("~/Scripts/")%>' + 'ui.datepicker-' + '<%=ViewData["LocalLanguage"]%>' + '.js';
                $.ajax({
                    url: datePickerScriptFilePath,
                    dataType: 'script',
                    async: false,
                    success: function () {
                        $("#StartDate").datepicker($.datepicker.regional['<%=ViewData["LocalLanguage"]%>']);
                        $("#divDialog form").attr("onSuccess", "loadPlaningsControl();");
                    }
                });
            });
        }

        function addTask() {
            openDialog('<%:Url.RouteUrl("Default", new {controller = "GlobalTasks", action = "Add"})%>', '<%:SystemManagersStrings.AddTask%>', function () {
                var datePickerScriptFilePath = '<%:Url.Content("~/Scripts/")%>' + 'ui.datepicker-' + '<%=ViewData["LocalLanguage"]%>' + '.js';
                $.ajax({
                    url: datePickerScriptFilePath,
                    dataType: 'script',
                    async: false,
                    success: function () {
                        $("#StartDate").datepicker($.datepicker.regional['<%=ViewData["LocalLanguage"]%>']);
                        $("#divDialog form").attr("onSuccess", "loadPlaningsControl();");
                    }
                });
            });
        }

        function loadPlaningsControl() {
            $("#planings").load(loadPlaningsControlLink, function () {
            });
        }

        function loadGlobalTasksByLevelAndPlaning(levelsSelectId, planingsSelectId, tasksSelectId, dateFieldId) {

            var selectedLevelValue = $("#" + levelsSelectId + " option:selected").val();
            var selectedPlaningValue = $("#" + planingsSelectId + " option:selected").val();
            var date = $("#" + dateFieldId).val();
            if (selectedLevelValue == "" || selectedPlaningValue == "" || date == "")
                return false;
            var link = '<%:Url.RouteUrl("Default", new {controller = "GlobalTasks", action = "ByLevelAndPlaningJSON"})%>' + '?levelId=' + selectedLevelValue + '&planingId=' + selectedPlaningValue + '&date=' + date;
            $.getJSON(link, function (data) {
                $("#" + tasksSelectId).empty();
                $(data).each(function () {
                    $("#" + tasksSelectId).append("<option value='" + this.id + "'>" + this.name + "</option>");
                });
            });
        }

        function taskDeleted() {
            $("div").RemoveBubblePopup();
            $("#planings").load(loadPlaningsControlLink, function () {

            });
        }      
                 
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <span class="titletext">
        <%:SystemManagersStrings.Planning%></span>
    <div class="addlink">
        <a href="javascript:void(0)" onclick=" addTask(); ">
            <%:SharedStrings.Add%></a></div>
    <div style="margin: 1em auto; position: relative; text-align: left; width: 763px;">
        <span>
            <%:SystemManagersStrings.Level%></span>
        <select id="LevelsSelect">
            <option>
                <%:SystemManagersStrings.ChooseLevel%></option>
            <%
                foreach (QualificationLevel level in Model)
                {%>
            <option value="<%:level.QualificationLevelId%>">
                <%:level.ToString()%></option>
            <%
                     }%>
        </select>
    </div>
    <div id="planings">
    </div>
</asp:Content>
